//
//  OtherLogInViewController.m
//  E_ChatRoom
//
//  Created by rimi1 on 15/6/27.
//  Copyright (c) 2015年 TJ. All rights reserved.
//

#import "OtherLogInViewController.h"

@interface OtherLogInViewController ()<UITextFieldDelegate>


/*手机号输入框*/
@property (nonatomic, strong)UITextField *phoneNumFiled;
/*密码输入框*/
@property (nonatomic, strong)UITextField *pswFiled;
/*登陆按钮*/
@property (nonatomic, strong)UIButton *loginBtn;
@end

@implementation OtherLogInViewController


/**
 *  重写init方法
 */
- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self.view.backgroundColor = [UIColor lightGrayColor];
        self.title = @"其他方式登陆";
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(dismissSelf)];
        self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    }
    return self;
}

#pragma mark - life circle methods

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self initializeUserInterface];
}

#pragma mark - textFiled Delegate method (textFiled代理方法)

/**
 *  退出键盘
 */
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [textField resignFirstResponder];
    return YES;
}


#pragma mark - private methods（私有方法）

/**
 *  初始化用户界面
 */
- (void)initializeUserInterface{
    
    //0.账号输入框
    CGFloat phoneNumFiledX = 40*Ratio;
    CGFloat phoneNumFiledY = 70*Ratio;
    CGFloat phoneNumFiledW = (ScreenWidth - phoneNumFiledX*2);
    CGFloat phoneNumFiledH = 28*Ratio;
    _phoneNumFiled = [[UITextField alloc] initWithFrame:CGRectMake(phoneNumFiledX, phoneNumFiledY, phoneNumFiledW, phoneNumFiledH)];
    _phoneNumFiled.delegate = self;
    _phoneNumFiled.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_phoneNumFiled];
    
    //1.密码输入框
    CGFloat pswFiledX = phoneNumFiledX;
    CGFloat pswFiledY = CGRectGetMaxY(_phoneNumFiled.frame) + 20*Ratio;
    CGFloat pswFiledW = (ScreenWidth - pswFiledX*2);
    CGFloat pswFiledH = 28*Ratio;
    _pswFiled = [[UITextField alloc] initWithFrame:CGRectMake(pswFiledX, pswFiledY, pswFiledW, pswFiledH)];
    _pswFiled.delegate = self;
    _pswFiled.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_pswFiled];
    
    //2.登陆
    CGFloat loginBtnW = pswFiledW;
    CGFloat loginBtnH = 30*Ratio;
    CGFloat loginBtnX = pswFiledX;
    CGFloat loginBtnY = CGRectGetMaxY(_pswFiled.frame) + 30*Ratio;
    _loginBtn = [[UIButton alloc] initWithFrame:CGRectMake(loginBtnX, loginBtnY, loginBtnW, loginBtnH)];
    [_loginBtn setTitle:@"登陆" forState:UIControlStateNormal];
    [_loginBtn setResizeN_BG:@"fts_green_btn" H_BG:@"fts_green_btn_HL"];
    _loginBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    _loginBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [_loginBtn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_loginBtn];
}

/**
 *  注册
 */
- (void)login{
    
    UserInfo *userInfo = [UserInfo sharedUserInfo];
    userInfo.user = self.phoneNumFiled.text;
    userInfo.pwd = self.pswFiled.text;
    
    [super login];
}

/**
 *  点击空白处，退出键盘
 */
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    [self.view endEditing:YES];
}

/**
 *  返回上一级
 */
- (void)dismissSelf{
    
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}

@end
